package net.jlibrary.member.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.annotation.JsonFormat;

import net.jlibrary.common.CoreConstants;
import net.jlibrary.common.core.annotation.CodeGenComment;
import net.jlibrary.common.core.annotation.SearchCondition;
import net.jlibrary.common.core.annotation.SearchField;
import net.jlibrary.common.core.entity.BaseObject;
import net.jlibrary.parking.domain.Parking;

@Entity(name = "t_member")
@Component
@BatchSize(size = 15)
@CodeGenComment(value = "会员管理", genSelect = true)
public class Member extends BaseObject {
	private static final long serialVersionUID = -8198353015224700158l;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@SearchField(value = "id", condition = SearchCondition.EQUAL)
	private Long id;
	private String nickname;
	private String phone;
	private String mailbox;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parking_id")
	@CodeGenComment(value = "停车场名称", viewList = true, viewSearch = true, required = true)
	private Parking parking;
	@JsonFormat(pattern = CoreConstants.DATETIME_FORMAT_DEFAULT, timezone = CoreConstants.DATE_TIMEZONE_DEFAULT) // 返回时间类型
	@DateTimeFormat(pattern = CoreConstants.DATETIME_FORMAT_DEFAULT) // 接收时间类型
	private Date startdate;
	@JsonFormat(pattern = CoreConstants.DATETIME_FORMAT_DEFAULT, timezone = CoreConstants.DATE_TIMEZONE_DEFAULT) // 返回时间类型
	@DateTimeFormat(pattern = CoreConstants.DATETIME_FORMAT_DEFAULT) // 接收时间类型
	private Date enddate;

	@Column(updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	@CodeGenComment(value = "创建时间", viewList = true)

	private Date createdate;
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastdate;;

	private boolean valid;

	@SearchField(value = "name", condition = SearchCondition.FUZZ_FULL)
	@Transient
	private String nameSearchKey;

	@SearchField(value = "parking", condition = SearchCondition.EQUAL)
	@Transient
	private Parking parkingSearchKey;

	public String getNameSearchKey() {
		return nameSearchKey;
	}

	public void setNameSearchKey(String nameSearchKey) {
		this.nameSearchKey = nameSearchKey;
	}

	public Parking getParkingSearchKey() {
		return parkingSearchKey;
	}

	public void setParkingSearchKey(Parking parkingSearchKey) {
		this.parkingSearchKey = parkingSearchKey;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Member other = (Member) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public Serializable getPrimaryKey() {
		// TODO Auto-generated method stub
		return id;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMailbox() {
		return mailbox;
	}

	public void setMailbox(String mailbox) {
		this.mailbox = mailbox;
	}

	public Parking getParking() {
		return parking;
	}

	public void setParking(Parking parking) {
		this.parking = parking;
	}

	public Date getStartdate() {
		return startdate;
	}

	public void setStartdate(Date startdate) {
		this.startdate = startdate;
	}

	public Date getEnddate() {
		return enddate;
	}

	public void setEnddate(Date enddate) {
		this.enddate = enddate;
	}

	public Date getCreatedate() {
		return createdate;
	}

	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	public Date getLastdate() {
		return lastdate;
	}

	public void setLastdate(Date lastdate) {
		this.lastdate = lastdate;
	}

	public boolean isValid() {
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

}
